<?php 
$model = new Administrator_Model_News_View();
$siteinfo = $model->GetSiteInfo();
$title = 'Danh sách danh mục';
$button = '<button class="add button" name="btadd" value="btadd" type="submit"></button>';
switch ($this->task) {
	case 'new':
	$title = 'Thêm danh mục';
	$button = '<button class="save button" name="btsave" value="btsave" type="submit"></button>';
	$button .= '<button class="back button" name="btback" value="btback" type="submit"></button>';
	$button .= '<button class="option button" name="btoption" value="btoption" type="submit"></button>';
	break;
	case 'edit':
	$title = 'Thay đổi thông tin danh mục';
	$button = '<button class="save button" name="btsave" value="btsave" type="submit"></button>';
	$button .= '<button class="back button" name="btback" value="btback" type="submit"></button>';
	$button .= '<button class="option button" name="btoption" value="btoption" type="submit"></button>';
	break;
	case 'list':
	$title = 'Danh sách danh mục';
	$button = '<button class="add button" name="btadd" value="btadd" type="submit"></button>';
	$button .= '<button class="edit button" name="btedit" value="btedit" type="submit"></button>';
	$button .= '<button class="delete button" name="btdelete" value="btdelete" type="submit"></button>';
	$button .= '<button class="able button" name="btable" value="btable" type="submit"></button>';
	$button .= '<button class="check button" name="btcheck" value="btcheck" type="submit"></button>';
	$button .= '<button class="option button" name="btoption" value="btoption" type="submit"></button>';
	break;
	default:
		;
	break;
}
?>
<form method="post" enctype="multipart/form-data">
<div class="nav">
	<div class="navbutton">
		<?php echo $button;?>
	</div>
</div>
<div class="sheet">
	<div class="mana-title"><?php echo $title?></div>
	<div class="intro">
		<div class="form">
		<div class="cat edit">
<?php 
	if($this->task != 'list'){
		if($this->task == 'edit'){
			$form = new Administrator_Form_News_Catalogue($this->id);
			$form->render();
		}
		if($this->task == 'new'){
			$form = new Administrator_Form_News_Catalogue('');
			$form->render();
		}?>
	</div><?php
	}
	else {
echo '<table class="list-item">';
	echo '<thead>';
		echo '<th class="stt">STT</th>';
		echo '<th class="checkbox"><input id="selectall" type="checkbox" ></th>';
		echo '<th class="">Tên Danh mục</th>';
		if($siteinfo['status']==1)echo '<th class="">Catalogue name</th>';
		echo '<th class="">Thể loại</th>';
		echo '<th class="count">Bài viết</th>';
		echo '<th class="option">View</th>';
		echo '<th class="action">Action</th>';
		echo '<th class="option">BVLQ</th>';
		echo '<th class="option">Date</th>';
		echo '<th class="option">DM</th>';
		echo '<th class="option">TL</th>';
		echo '<th class="option">Tag</th>';
		echo '<th class="option">Hit</th>';
		echo '<th class="option">User</th>';
		echo '<th class="option">Social</th>';
		echo '<th class="option">Key</th>';
		echo '<th class="id">ID</th>';
	echo '</thead>';
	echo '<tbody>';
	$i=1;
	foreach ($model->GetAllCatalogue() as $value) {
		$class="";if($i%2==0)$class = 'focus';
		echo '<tr class="'.$class.'">';
			echo '<td class="stt">'.$i.'</td>';
			echo '<td class="checkbox"><input id="'.$value['id'].'" type="checkbox" name="'.$value['id'].'" ></td>';
			echo '<td class="">'.$model->TranslateByLang($value['name'], 'vi').'</td>';
			if($siteinfo['status']==1)echo '<td class="">'.$model->TranslateByLang($value['name'], 'en').'</td>';
			$secinfo = $model->GetSectionInfo($value['section']);
			$title = $model->TranslateByLang($secinfo['name'], 'vi');
			if($siteinfo['status']==1) $title = $model->TranslateByLang($secinfo['name'], 'vi').' - '.$model->TranslateByLang($secinfo['name'], 'en');
			echo '<td class="">'.$title.'</td>';
			echo '<td class="count">'.$model->countContentinCat($value['id']).'</td>';
			$feature = '<img src="'.$this->dirImg.'/uncheck.png">';
			if($value['view'] == '0') $feature = '<img src="'.$this->dirImg.'/check.png">'; 
			echo '<td class="option"><a href="#" onclick="Showrelated('.$value['id'].')">'.$feature.'</a></td>';
			echo '<td class="action"><a href="'.BASE_URL.'/administrator/news/catalogue?task=edit&id='.$value['id'].'"><img src="'.$this->dirImg.'/edit.png"></a><a href="#" onclick="DeleteSection()"><img src="'.$this->dirImg.'/delete.png"></a></td>';
			//show related
			$feature = '<img src="'.$this->dirImg.'/uncheck.png">';
			if($value['showrelated'] == '0') $feature = '<img src="'.$this->dirImg.'/check.png">'; 
			echo '<td class="option"><a href="#" onclick="Showrelated('.$value['id'].')">'.$feature.'</a></td>';
			//show date
			$feature = '<img src="'.$this->dirImg.'/uncheck.png">';
			if($value['showdate'] == '0') $feature = '<img src="'.$this->dirImg.'/check.png">'; 
			echo '<td class="option"><a href="#" onclick="Showdate('.$value['id'].')">'.$feature.'</a></td>';
			
			//show cat
			$feature = '<img src="'.$this->dirImg.'/uncheck.png">';
			if($value['showcat'] == '0') $feature = '<img src="'.$this->dirImg.'/check.png">'; 
			echo '<td class="option"><a href="#" onclick="Showcat('.$value['id'].')">'.$feature.'</a></td>';
			
			//show sec
			$feature = '<img src="'.$this->dirImg.'/uncheck.png">';
			if($value['showsec'] == '0') $feature = '<img src="'.$this->dirImg.'/check.png">'; 
			echo '<td class="option"><a href="#" onclick="Showsec('.$value['id'].')">'.$feature.'</a></td>';
			
			//show tag
			$feature = '<img src="'.$this->dirImg.'/uncheck.png">';
			if($value['showtag'] == '0') $feature = '<img src="'.$this->dirImg.'/check.png">'; 
			echo '<td class="option"><a href="#" onclick="Showtag('.$value['id'].')">'.$feature.'</a></td>';
			
			//showhit
			$feature = '<img src="'.$this->dirImg.'/uncheck.png">';
			if($value['showhit'] == '0') $feature = '<img src="'.$this->dirImg.'/check.png">'; 
			echo '<td class="option"><a href="#" onclick="Showhit('.$value['id'].')">'.$feature.'</a></td>';
			
			//showuser
			$feature = '<img src="'.$this->dirImg.'/uncheck.png">';
			if($value['showuser'] == '0') $feature = '<img src="'.$this->dirImg.'/check.png">'; 
			echo '<td class="option"><a href="#" onclick="Showuser('.$value['id'].')">'.$feature.'</a></td>';
			
			//showsocial
			$feature = '<img src="'.$this->dirImg.'/uncheck.png">';
			if($value['showsocial'] == '0') $feature = '<img src="'.$this->dirImg.'/check.png">'; 
			echo '<td class="option"><a href="#" onclick="Showsocial('.$value['id'].')">'.$feature.'</a></td>';
			
			//showkey
			$feature = '<img src="'.$this->dirImg.'/uncheck.png">';
			if($value['key'] == '0') $feature = '<img src="'.$this->dirImg.'/check.png">'; 
			echo '<td class="option"><a href="#" onclick="Showkey('.$value['id'].')">'.$feature.'</a></td>';
			echo '<td class="id">'.$value['id'].'</td>';
			echo '</tr>';
		$i++;
	}
	echo '</tbody>';
	echo '<tfoot>';
	echo '</tfoot>';
echo '</table>';
}
?>		
<script type="text/javascript">
function Showrelated(ID) {
    $.ajax({
          type: "POST",
          url: '<?php echo BASE_URL.'/administrator/news/catalogueshowrelated';?>',
          data: { catid: ID },
          success: function (result) {
          window.location.reload()
          }
     });
}    
function Showdate(ID) {
    $.ajax({
          type: "POST",
          url: '<?php echo BASE_URL.'/administrator/news/catalogueshowdate';?>',
          data: { catid: ID },
          success: function (result) {
          window.location.reload()
          }
     });
}

function Showcat(ID) {
    $.ajax({
          type: "POST",
          url: '<?php echo BASE_URL.'/administrator/news/catalogueshowcat';?>',
          data: { catid: ID },
          success: function (result) {
          window.location.reload()
          }
     });
}

function Showsec(ID) {
    $.ajax({
          type: "POST",
          url: '<?php echo BASE_URL.'/administrator/news/catalogueshowsec';?>',
          data: { catid: ID },
          success: function (result) {
          window.location.reload()
          }
     });
}

function Showtag(ID) {
    $.ajax({
          type: "POST",
          url: '<?php echo BASE_URL.'/administrator/news/catalogueshowtag';?>',
          data: { catid: ID },
          success: function (result) {
          window.location.reload()
          }
     });
}

function Showhit(ID) {
    $.ajax({
          type: "POST",
          url: '<?php echo BASE_URL.'/administrator/news/catalogueshowhit';?>',
          data: { catid: ID },
          success: function (result) {
          window.location.reload()
          }
     });
}

function Showuser(ID) {
    $.ajax({
          type: "POST",
          url: '<?php echo BASE_URL.'/administrator/news/catalogueshowuser';?>',
          data: { catid: ID },
          success: function (result) {
          window.location.reload()
          }
     });
}
function Showsocial(ID) {
    $.ajax({
          type: "POST",
          url: '<?php echo BASE_URL.'/administrator/news/catalogueshowsocial';?>',
          data: { catid: ID },
          success: function (result) {
          window.location.reload()
          }
     });
}
function Showkey(ID) {
    $.ajax({
          type: "POST",
          url: '<?php echo BASE_URL.'/administrator/news/catalogueshowkey';?>',
          data: { catid: ID },
          success: function (result) {
          window.location.reload()
          }
     });
}
</script>
		</div>
	</div>
</div>
</form>